import mongoose from "mongoose"
import colors from "colors"
/* 连接数据库 */
const connectDB = async () =>{
  try {
    const conn = await mongoose.connect(process.env.DBHOST, {
      useUnifiedTopology: true,
      useNewUrlParser: true,
      // useCreateIndex: true
    })
    console.log(`数据库连接成功: ${conn.connection.host}`.cyan)
    return conn
  } catch (err) {
    console.log(`error: ${err.message}`.red) 
    process.exit(1)
  }
}

export default connectDB